package indi.kider.server.schedule.job;

import indi.kider.server.schedule.service.BusService;
import indi.kider.server.schedule.service.HmService;
import indi.kider.server.schedule.service.ProduceBillSerivce;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by qs on 2018/7/31.
 */
@Component
@Configurable
@EnableScheduling
@EnableAsync
@Slf4j
public class BusJobBeans {

    @Autowired
    BusService busService;
    @Autowired
    HmService hmService;

    @Autowired
    ProduceBillSerivce produceBillSerivce;
    /**
     * 更新服务提醒状态
     * 1小时监测 单位毫秒
     */
    @Async
    @Scheduled(fixedRate = 1000 * 60 * 5)
    public void updateBusWarningState() {
        busService.updateBusWarningState();
    }


    /**
     * 抽取公寓每日入住率统计
     * 每天早上1点运行,记为昨天的统计数据
     */
    @Async
    @Scheduled(cron = "0 0 1 * * ?")
    public void batchInsertCntReport() {
        busService.batchInsertCntReport();
    }


    /**
     * 定时任务,清除本月退租用户密码卡指纹，调用NB接口
     */
    @Async
    @Scheduled(cron = "0 0 */2 * * ?")
    public void clearPwdCardFg() {
        hmService.clearPwdCardFg();
    }
    /**
     * 生产租房账单
     * 每天11点
     */
    @Async
    @Scheduled(cron = "0 0 23 * * ?")
    public void produceRentBill() {
        produceBillSerivce.produceRentBill();
    }


    /**
     * 生产租房后付费账单
     * 每月1号凌晨8点启动
     */
    @Async
    @Scheduled(cron = "0 0 8 1 * ?")
    public void produceAllRentBill() {
        log.info("【定时任务开始计算付费账单。】");
        produceBillSerivce.produceThisMonthBill();
    }

    /**
     * 生产租房账单
     * 每天3点
     */
    @Async
    @Scheduled(cron = "0 0 3 * * ?")
    public void extractRentInfo() {
        produceBillSerivce.extractRentInfo();
    }

    /**
     * 每天8:30开始执行每天的预付费账单
     */
    @Async
    @Scheduled(cron = "0 30 8 * * ?")
    public void produceEveryDayBill() {
        log.info("【开始执行每日的预付费账单】");
        produceBillSerivce.produceEveryDayBill();
    }

    /**
     * 每天8:50开始执行每天的预付费账单的扣费
     */
    @Async
    @Scheduled(cron = "0 50 8 * * ?")
    public void settlementBillEveryDay() {
        log.info("【开始对每日的预付费账单进行钱包扣费】");
        produceBillSerivce.settlementBillEveryDay();
    }

    /**
     * 朝九晚五时间段内 每30分钟执行一次。
     */
    @Async
    @Scheduled(cron = "0 0/10 * * * ?")
    public void regitWallet() {
        log.info("【对未注册的账户进行注册】");
        produceBillSerivce.regitWallet();
    }

}
